package me.fanx.springcloud.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import me.fanx.springcloud.remote.HelloRemote;

@RestController
public class ConsumerController {
    private Logger log = LoggerFactory.getLogger(ConsumerController.class);

    @Autowired
    private HelloRemote helloRemote;

    @GetMapping("/hello/{name}")
    public String index(@PathVariable("name") String name) {
        log.info("request /hello/{}", name);
        try {
            String result = helloRemote.hello(name);
            log.info("remote result: {}", result);
            return result;
        } catch (Exception e) {
            return "Exception: " + e.getMessage();
        }
    }

}